Box::Calc - Packing Algorithm
version 0.0500
use Box::Calc; my $box_calc = Box::Calc->new(api_key => 'xxx'); # define the possible box types $box_calc->add_box_type( x => 12, y => 12, z => 18, weight => 16, name => 'big box' ); $box_calc->add_box_type( x => 4, y => 6, z => 8, weight => 6, name => 'small box' ); # define the items you want to put into boxes $box_calc->add_item( 3, { x => 6, y => 3, z => 3, weight => 12, name => 'soda' }); $box_calc->add_item( 1, { x => 3.3, y => 3, z => 4, weight => 4.5, name => 'apple' }); $box_calc->add_item( 2, { x => 8, y => 2.5, z => 2.5, weight => 14, name => 'water bottle' }); # get a packing list synchronously my $packing_list = $box_calc->packing_list->recv; # get a packing list asynchronously my $cv = $box_calc->packing_list; # ... do stuff ... my $packing_list = $cv->recv;
Box::Calc helps you determine what can fit into a box for shipping or storage purposes. It will try to use the smallest box possible of the box types. If every item won't fit into your largest box, then it will span the boxes letting you know how many boxes you'll need.
Once it's done packing the boxes, you can get a packing list for each box, as well as the weight of each box.
When adding items, be sure to use the outer most dimensions of oddly shaped items, otherwise they may not fit the box.
When adding box types, be sure to use the inside dimensions of the box. If you plan to line the box with padding, then subtract the padding from the dimensions, and also add the padding to the weight of the box.
What units you use (inches, centimeters, ounces, pounds, grams, kilograms, etc) don't matter as long as you use them consistently.
Constructor.
An API Key from http://www.boxcalc.net.
Adds a new Box::Calc::BoxType to the list of box_types. Returns the newly created Box::Calc::BoxType instance.
box_types
The list of constructor parameters for Box::Calc::BoxType.
Registers a new item. Returns the new item registered.
The constructor parameters for the Box::Calc::Item.
Returns a data structure with all the item names and quantities packed into boxes. This can be used to generate manifests.
[ { # box one id => "xxx", name => "big box", weight => 30.1, packing_list => { "soda" => 3, "apple" => 1, "water bottle" => 2, } } ]
Returns a data structure with all the item names and quantities packed into boxes, and all the shipping methods and prices. This can be used to provide shipping pricing options.
{ 'USPS Parcel Post' => { postage => 11.12, number_of_parcels => 1, weight => 30.1, parcels => [ { # box one id => "xxx", name => "big box", weight => 30.1, packing_list => { "soda" => 3, "apple" => 1, "water bottle" => 2, }, shipping => { postage => 11.12, } } ] } }
A hash of parameters that affect the results returned.
A 5 digit zip code where the packages will originate from.
A 5 digit zip code (if shipping inside the United States) or the name of a country (if shipping outside the United States).
Moose Ouch AnyEvent AnyEvent::HTTP::LWP::UserAgent JSON
http://github.com/rizen/Box-Calc
http://github.com/rizen/Box-Calc/issues
Although these modules don't solve the same problem as this module, they may help you build something that does if Box::Calc doesn't quite help you do what you want.
Box::Calc is Copyright 2012 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.
To install Box::Calc, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Box::Calc
CPAN shell
perl -MCPAN -e shell install Box::Calc
For more information on module installation, please visit the detailed CPAN module installation guide.