Split an order across warehouses
Fulfilment needs the order regrouped by the warehouse each line ships from, so it can raise one pick list per site.
- Group the SKUs under their warehouse code.
- Within a warehouse, keep the order the lines arrived in.
- A warehouse with no lines does not appear at all.
SplitByWarehouse(rows: list<Row>) → map<string, list<string>>
C# needs a compiler and Drill does not host one yet, so this page is the reference rather than an exercise: the problem, worked examples, and the solution in full. To type it out, the same problem runs in Python.
Where you start
public Dictionary<string, List<string>> SplitByWarehouse(List<Row> rows) {
}
Worked examples
| Call | Result |
|---|---|
SplitByWarehouse(new List<Row> { new Row("A1", "IST"), new Row("B2", "ANK"), new Row("C3", "IST") }) | new Dictionary<string, List<string>> { { "IST", new List<string> { "A1", "C3" } }, { "ANK", new List<string> { "B2" } } } |
SplitByWarehouse(new List<Row> { new Row("A1", "IST") }) | new Dictionary<string, List<string>> { { "IST", new List<string> { "A1" } } } |
SplitByWarehouse(new List<Row> { }) | new Dictionary<string, List<string>> { } |
SplitByWarehouse(new List<Row> { new Row("X", "IZM"), new Row("X", "IZM") }) | new Dictionary<string, List<string>> { { "IZM", new List<string> { "X", "X" } } } |
Hint
A map from code to a growing list. Create the list the first time you meet a code.
Reference solution in C#
public Dictionary<string, List<string>> SplitByWarehouse(List<Row> rows) {
var result = new Dictionary<string, List<string>>();
foreach (var r in rows) {
if (!result.ContainsKey(r.Warehouse)) result[r.Warehouse] = new List<string>();
result[r.Warehouse].Add(r.Sku);
}
return result;
}