SHOW ME WHAT YOU GOT (Part 8): From ERP to Route Planning
Part 7 left the regional manager with an approved change and a way to see which bookings it would help. A stock transfer gives her one more question. Who is going to get it across town, and can they get there before the first treatment needs it?
Market Street has two bottles of the gel King Street is about to run out of. King Street needs them by 10.30. The driver is already taking a box from the depot to West Street, which can take deliveries until noon. Should she drop the box first, or pick up the gel while she's across town?
In Part 7, Making It Pay, a transfer was a proposal to move stock between two branches. Give each branch a latitude and longitude and we can ask whether the transfer fits into the driver's day. This is the next step in the Guerilla Architecture approach. The useful result for the rest of the application is an estimated receipt time at King Street. The booking planner can use it to see which treatments the transfer could save.
The branch has a location. The transfer has a deadline.
Store coordinates on the branch and use them to get road travel times between the depot and the branches on the run. A matrix can be asymmetric. The trip out might take 18 minutes and the trip back 25. Keep a fixed matrix in the C# fixture so anyone can run it. In the real adapter, choose a travel estimate appropriate to the departure period.
public sealed record Branch(string Id, double Latitude, double Longitude);
public sealed record Transfer(
string FromBranchId,
string ToBranchId,
string Sku,
int Units,
TimeOnly ReadyAt,
TimeOnly NeededBy);
The routing input adds the driver's shift, the van's capacity and the minutes needed to load or unload at each stop. The transfer produces two stops. Both belong on the same van run, and the pickup must come before the drop. A route with time windows carries a clock through the sequence, adding travel, handling time and any wait for a branch to open. It also carries the van's load, which can increase at a pickup and decrease at a delivery. OR-Tools time windows · OR-Tools pickup and delivery
A shorter run that arrives too late
Suppose the driver leaves the depot at 9.30 with West Street's box. Each stop takes five minutes. Here are two candidate sequences from a fictional road matrix. The return to the depot counts in the driving time.
| Sequence | Driving time | Gel unloaded at King Street | Result |
|---|---|---|---|
| West, Market, King | 68 min | 10.35 | Misses the gel deadline |
| Market, King, West | 75 min | 10.13 | Both deliveries fit |
The leg times for the short run are 14, 18, 18 and 18 minutes. For the second run they are 15, 18, 19 and 23. West Street's box is unloaded by 10.37 on the second run. Seven extra minutes behind the wheel buys a delivery that can actually save the bookings.
With one driver and a few stops, the teaching sample can enumerate the orders, reject those that break a window or pickup dependency, and compare what remains. A larger sample could replace that search with the routing solver and keep the same branch and transfer records. OR-Tools vehicle routing
What changes in the ERP?
The shift planner already cares where a technician is before and after a move. The van makes that dependency unavoidable. The cost of adding King Street depends on the stop before it and the stop after it. Packing still gives us the stock, driver and van capacity constraints. Routing supplies the order and times for those commitments.
Keep the proposed receipt in the planning view. Approval commits the stock at Market Street and the time on the driver's run. Collection puts the stock in transit. The receipt makes it available at King Street. If the receipt slips, look up the appointments that depended on it and show the manager which plans still work. If we can choose which optional transfers to attempt, compare the bookings saved and the van time spent across the whole run.
Why is Market Street always late on Fridays?
The route says five minutes to collect the gel. On Fridays the van is usually there for fifteen. Is the driver stuck in traffic, waiting for somewhere to park, or waiting for somebody to come out with the stock?
Record arrival, handover start and departure separately. Record when the stock was ready and which appointments were still running when the van arrived. Now the time between branches can teach us about the road, and the time between arrival and handover can teach us about the branch. If the same technician has to finish a removal and sign out the gel, both jobs use that person's time. Put the handover on the rota and the planner can see the clash before the van leaves.
public sealed record StopObservation(
string BranchId,
DateTimeOffset Arrived,
DateTimeOffset HandoverStarted,
DateTimeOffset Departed,
DateTimeOffset? StockReady,
int AppointmentsRunningAtArrival);
var waiting = observation.HandoverStarted - observation.Arrived;
var handling = observation.Departed - observation.HandoverStarted;
Keep the previous stop and its departure time on the trip record. Those let us group road delays by direction, weekday and time of day. Group handover delays by branch and receiving conditions. Start with coarse time bands and use the branch's overall history when Friday mornings have too few observations. For a new route, use the appointment load we expect at arrival. The observed load tells us afterwards whether that assumption was any good.
Suppose Market Street's Friday pickup takes fifteen minutes instead of five. The route through Market Street first now gets the gel unloaded at King Street at 10.23. We've used ten of our seventeen spare minutes. If pickup regularly takes more than twenty-two minutes all in, the 10.30 deadline is at risk even with the better order. The manager can have the stock ready before the van arrives, assign somebody else to hand it over, or leave earlier. Run those alternatives against the same travel and handover scenarios and look at how often the gel arrives in time. If we try staging stock in advance, record which runs used it and compare pickup waits on similar Fridays. The Friday pattern alone can't tell us how much staging will help.
The same delivery changes the next round of appointments. King Street can plan around a proposed receipt and use the stock once it lands. Market Street needs enough stock left for its own customers, plus someone free to make the handover. The branch records now feed a forecast, the forecast feeds the route, and the route puts new commitments on those same records. That's the extension from scheduling to regional planning again, with the van taking its place beside the technician and the station.
The diary changes while the van is out
Try the same run with a different morning. At 9.50 the driver has both loads on board and is about to leave Market Street. West Street is next. King Street has just taken an enquiry for a treatment that would contribute £45 after direct costs. They can book it if the gel is unloaded by 10.30. The stock had been going to King Street anyway. Now its arrival time matters.
The route preview starts from Market Street with the stock already in the van. Only the unfinished stops can move. Here are the remaining legs in this fixture, including the return to the depot.
| Remaining route | Driving minutes | King unloaded | West unloaded | Back at depot |
|---|---|---|---|---|
| West, King, depot | 53 | 10.35 | 10.09 | 10.53 |
| King, West, depot | 60 | 10.13 | 10.37 | 11.00 |
West can still receive the box by noon and the driver is due back by 11.30. For the fixture, price extra driving at £1 a minute and charge £3 for changing a dispatched plan. With no appointment to save, keep the route. With £45 in additional contribution, change it. The expected gain under these fixed times is £45 − £7 − £3 = £35.
flowchart LR
A["King Street receives an enquiry"] --> B["Look up stock and treatment deadline"]
B --> C["Read van position, stock and stops still open"]
C --> D["Compare keeping the route with visiting King first"]
D --> E["Check existing delivery promises and driver shift"]
E --> F["Show revised receipt time and gain"]
F --> G["Dispatcher approves and driver receives update"]
G --> H["Record receipt and update the appointment plan"]
H --> I["Use actual travel and handover times on the next run"]
The RegionalSalon sample runs this two-order decision in DeliveryRerouting.cs. It projects each route from the current departure time using fixed leg times and five minutes at each stop. It filters out routes that break the existing delivery or shift deadline, then scores the eligible routes in pounds. The sample compares the same two orders with and without the new booking. It uses a fictional matrix, and stops at the recommendation.
Run it with dotnet run --project samples/RegionalSalon -c Release. The last two lines show what changed:
King appointment worth £0: West then King, gain over current route £0
King appointment worth £45: King then West, gain over current route £35
When travel or handover times vary, replay both orders against the same scenarios and count the share that get the gel there before 10.30. If King first makes it 80% of the time and the current route makes it 20%, the extra chance of serving a confirmed £45 booking is worth £27 before change costs. For an enquiry still awaiting acceptance, account for that uncertainty too. A predicted arrival is useful to the dispatcher. The confirmed receipt is what puts the gel on the shelf.
This is where the appointment and delivery planners can help each other. The booking record gives the shipment a deadline and a reason to move. The route gives the booking desk an arrival estimate. When a dispatcher approves an update, the live version of the system would send the changed sequence to the driver and track acknowledgement. If another enquiry comes in before then, it can be included in the next comparison alongside the promises already made.