Im developing an eCommerce system where items are 'logically' placed into boxes. Rather than the shipping system calculating the shipping of each item individually. The shipping will be calculated by each box sent.
1,2 or more items can be placed in each box.
- Each BOX has a HxWxD (Rectangualr)
- Each item also has a HxWxD.
- A box can hold many items until full/no space left
Calculating the first item is easy, just have to figure if the item is smaller than the box, but how would I calculate the remaining space ?
Even for two items the problem isn't trivial. Let a box $W_b\times H_b\times D_b$ and a first item $W_1\times H_1\times D_1$. There could be three ways to place it in the box (or just two if you may not tilt the item, or less if the dimensions do not fit), leaving an L-shaped free space on the bottom.
And for all 3 placements, you can try 3 placements of the second item, in the two sections of the L, and also on top of the first item.
You will need to check constraints like $$W_1+W_2\le W_b,$$ $$H_1, H_2\le H_b,$$ $$D_1, D_2\le D_b,$$ or $$W_1+D_2\le W_b,$$ $$D_1, W_2\le H_b,$$ $$H_1, D_2\le D_b,$$ depending on the respective item orientations and the faces of contact.
(Not mentioning the possibility to place items obliquely...)