INTEGRATION / ROUTE-LOADING

Load a van in route order within axle limits

Load a van so every stop's goods come out first, no axle is overloaded, and the loader gets a step list that never blocks a door.

WHERE IT SITS

Between route planning and the loading bay: a TMS or dispatcher knows the stops and the van, and the bay needs to know what goes in first.

HOW THE DATA FLOWS
  1. 01

    The route arrives as items with a stop_index; stop 0 is delivered first.

  2. 02

    The van declares its door (access_directions) and both axles with their positions and limits.

  3. 03

    pack() keeps each stop's goods in front of later stops and refuses any placement that would overload an axle; a drop it cannot take legally is named.

  4. 04

    safeLoadingOrder() and buildExecutionPlan() give the loader steps that slide in through the door without passing anything already loaded.

THE WHOLE PROGRAM, IN Node / JavaScript
import { explainUnpackedItem, pack, safeLoadingOrder } from '@packvium/engine';
import { buildExecutionPlan } from '@packvium/engine/execution.js';

// Today's route from the TMS: three drops, stop 0 is delivered first.
const drop = (id, stop, weight) => ({
  id, stop_index: stop, quantity: 1, weight, keep_upright: true, must_be_on_floor: true,
  dimensions: { length: '1100', width: '1100', height: '1000' },
});
const request = {
  items: [drop('bakery', 0, '350 kg'), drop('cafe', 1, '250 kg'), drop('kiosk', 2, '150 kg')],
  containers: [{
    id: 'van', quantity: 1, max_payload: '1500 kg',
    inner_dimensions: { length: '3600', width: '1200', height: '1400' },
    access_directions: ['+x'],                      // the only door is at the back
    axles: [{ position: '500', max_load: '600 kg' }, { position: '2800', max_load: '700 kg' }],
  }],
  configuration: { effort_budget: { max_candidates_evaluated: 1000000 } },
};

const result = pack(request);
// A drop the van cannot take legally comes back with a reason the dispatcher can read.
for (const left of result.unpacked_items) console.log('left behind:', left.item_id, explainUnpackedItem(left));

// Turn the answer into steps for the loader: last drop in first, nothing passes what is loaded.
const [van] = result.containers;
const ticks = (box) => ({ length: box.length.ticks, width: box.width.ticks, height: box.height.ticks });
const order = safeLoadingOrder(
  van.placements.map((placement) => ({
    origin: { x: placement.position.x.ticks, y: placement.position.y.ticks, z: placement.position.z.ticks },
    dimensions: ticks(placement.dimensions),
  })),
  ticks(van.inner_dimensions),
  ['+x'],
);
const plan = buildExecutionPlan(request, result, { loadingOrders: { 0: order } });
console.log(plan.containers[0].steps.map((step) => step.placement.item_type).join(' -> '));
WHAT IT DOES

All three drops fit, and the loading steps run kiosk, cafe, bakery: the last stop goes in first, against the cab, and the first stop is by the door. Both axles stay inside their limits; tighten the rear limit and the heaviest drop is left behind with a reason instead of being loaded illegally.

Every program on these pages is run exactly as printed by this site's test suite, against the published package, on every change.

WHAT TO KEEP

The execution plan with the route it was built for. A late change to the route is a new request, and a change on the dock is a revision of this plan (see the replanning integration).

WHEN THE ENGINE SAYS NO

A drop left behind comes back in unpacked_items, and explainUnpackedItem() turns it into a sentence a dispatcher can act on - send a second van, or move the drop to another route - instead of a load that would be illegal to drive.

INSTALL
npm install @packvium/engine