JT Smith > Box-Calc-0.0501 > Box::Calc

Download:
Box-Calc-0.0501.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.0501   Source  

NAME ^

Box::Calc - Packing Algorithm

VERSION ^

version 0.0501

SYNOPSIS ^

 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;

DESCRIPTION ^

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.

Tips

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.

METHODS ^

new(api_key)

Constructor.

api_key

An API Key from http://www.boxcalc.net.

add_box_type(params)

Adds a new Box::Calc::BoxType to the list of box_types. Returns the newly created Box::Calc::BoxType instance.

params

The list of constructor parameters for Box::Calc::BoxType.

add_item(quantity, params)

Registers a new item. Returns the new item registered.

params

The constructor parameters for the Box::Calc::Item.

packing_list()

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,
        }
    }
 ]

shipping_options( params )

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,
                }
            }
        ]
    }
 }
params

A hash of parameters that affect the results returned.

from

A 5 digit zip code where the packages will originate from.

to

A 5 digit zip code (if shipping inside the United States) or the name of a country (if shipping outside the United States).

PREREQS ^

Moose Ouch AnyEvent AnyEvent::HTTP::LWP::UserAgent JSON

SUPPORT ^

Repository

http://github.com/rizen/Box-Calc

Bug Reports

http://github.com/rizen/Box-Calc/issues

SEE ALSO ^

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.

Algorithm::Knapsack
Algorithm::Bucketizer
Algorithm::Knap01DP

AUTHOR ^

JT Smith <jt_at_plainblack_dot_com>
Colin Kuskie <colink_at_plainblack_dot_com>

LEGAL ^

Box::Calc is Copyright 2012 Plain Black Corporation (http://www.plainblack.com) and is licensed under the same terms as Perl itself.

syntax highlighting: