Regarding your new branch addressing this max in vehicle time constraint, I think Phil raised a valid point. The root cause is that the states are not updated when pickupShipment insertion position is determined.
Assume you have the following route and act start/end times: Start, P1, D1, End (0,10,20,30), where 10 is end time of P1 and 20 is start time of D1. Now you try to insert shipment (P2, D2).
Assume other constraints force the insertion to be Start, P2, P1, D2, D1, End (0, 10, 20, 30, 40, 50), where 10 is end time of P2, 20 is end time of P1, 30 is start time of D2 and 40 is start time of D1. Assuming both shipments have max in vehicle time 20, thus the insertion should be valid.
However, when you try to insert the new shipment, you insert P2 first. P2 is determined to be inserted between Start and P1, and now P1 end time delays to 20, thus the latestStart of D1 needs to update to 40. But it is not. It is still 30. Now you try to insert D2, which will delay D2 start time to 40, which is later than 30, thus the insertion will be disallowed.
At the end of this reply is the code of the example. Meanwhile you need the following line, which together with the priority makes sure that s1 is inserted first.
Please let me know what you think. Thanks.
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("type").build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("veh").setType(vehicleType)
Shipment shipment1 = Shipment.Builder.newInstance("s1")
Shipment shipment2 = Shipment.Builder.newInstance("s2")
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()