Two Dimensions, Fewest Pallets
The Christmas rush is on, and every truck that leaves the warehouse is money: each pallet slot costs freight, so dispatch wants shipment lines packed onto as few pallets as the physics allow. A pallet has two hard limits — a weight cap and a volume cap — and a load plan that breaches either one gets rejected at the dock. You are building the load planner: the little bin-packing engine that turns a pile of shipment lines into a tight, valid, reproducible pallet plan.
Requirements
The starter contains one table — keep it exactly as shipped, the grading tests seed and read it:
"Pallet Shipment Line" — one row per shipment line waiting to be palletized:
"Line No."—Integer, the primary keyWeight—Decimal, what the line weighs; never changesVolume—Decimal, the space the line takes; never changes"Pallet No."—Integer, your output: which pallet the line rides on;0until you assign it
Create a codeunit named "Pallet Loader" with one public procedure:
procedure BuildLoad(var PalletShipmentLine: Record "Pallet Shipment Line"; MaxWeight: Decimal; MaxVolume: Decimal): IntegerRules:
- A load plan is valid when every line sits on exactly one pallet and, on every pallet, the lines'
Weightvalues sum to at mostMaxWeightand theirVolumevalues sum to at mostMaxVolume. Both caps bind on every pallet, always — a pallet with spare weight capacity still overflows when the volumes breach their cap. - If any single line has
Weightgreater thanMaxWeightorVolumegreater thanMaxVolume, no load plan exists: fail with an error whose text contains the wordfit(lowercase) and the"Line No."of the offending line, and leave every"Pallet No."at0— a failed build writes nothing. If several lines are oversized, report the lowest"Line No."among them (the grading fixtures only ever seed one, so this tie-break is not graded).
Solve it with Pro
You’re reading the opening of the statement. Pro unlocks the whole problem:
- The full statement
- Starter code in the browser editor
- 11 grading tests, run on Business Central 28.5
- 3 hints
- The reference solution
Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.
Already on Pro? Sign in