NAME
Business::FedEx::RateRequest - Perl extension for getting available rates from Fedex using their Web Services API.
SYNOPSIS
use Business::FedEx::RateRequest;
use Data::Dumper;
# Get your account/meter/key/password numbers from Fedex
my %rate_args;
$rate_args{'account'} = '_your_account_number_';
$rate_args{'meter'} = '_your_meter_number_';
$rate_args{'key'} = '_your_key_';
$rate_args{'password'} = '_your_password_';
$rate_args{'uri'} = 'https://gatewaybeta.fedex.com:443/xml/rate';
my $Rate = new Business::FedEx::RateRequest(%rate_args);
my %ship_args;
$ship_args{'src_zip'} = '83835';
$ship_args{'dst_zip'} = '55411';
$ship_args{'weight'} = 5;
my $rtn = $Rate->get_rates(%ship_args);
if ( $rtn ) { print Dumper $rtn }
else { print $Rate->err_msg() }
Should return something like
$VAR1 = [
{
'ship_cost' => '112.93',
'ServiceType' => 'FIRST_OVERNIGHT'
},
{
'ship_cost' => '48.91',
'ServiceType' => 'PRIORITY_OVERNIGHT'
},
{
'ship_cost' => '75.04',
'ServiceType' => 'STANDARD_OVERNIGHT'
},
{
'ship_cost' => '42.84',
'ServiceType' => 'FEDEX_2_DAY'
},
{
'ship_cost' => '28.81',
'ServiceType' => 'FEDEX_EXPRESS_SAVER'
},
{
'ship_cost' => '7.74',
'ServiceType' => 'FEDEX_GROUND'
}
];
DESCRIPTION
This object uses a simple XML/POST instead of the slower and more complex Soap based method to obtain available rates between two zip codes for a given package weight and size. At the time of this writing FedEx evidently encourages the use of Soap to get available rates and provides source code examples for Java, PHP, C# but no Perl. FedEx doesn't provide non-Soap XML examples that I could find. Took me a while to develop the XML request but it returns results faster than the PHP Soap method.
The XML returned is voluminous, over 30k bytes to return a few rates, but is smaller than the comparable Soap results.
The URI's are not published anywhere I could find but I was successful in using
Test: https://gatewaybeta.fedex.com:443/xml/rate Production: https://gateway.fedex.com:443/xml
Early Beta modules and notes may be available at:
http://perlworks.com/cpan
If you use this module and have comments or suggestions please let me know.
METHODS
- $obj->new(%hash)
-
The new method is the constructor.
The input hash must include the following:
uri => FedEx URI (test or production) account => FedEx Account meter => FedEx Meter Number key => FedEx Key password => FedEx Password
- $obj->get_rates(%hash)
-
The input must include the following
src_zip => Source Zip Code dst_zip => Source Zip Code weight => Package weight in lbs
However the following are optionally and can override the defaults as noted
unless ( $args{'src_country'} ) { $args{'src_country'} = 'US' } unless ( $args{'dst_country'} ) { $args{'dst_country'} = 'US' } unless ( $args{'weight_units'} ) { $args{'weight_units'} = 'LB'} unless ( $args{'size_units'} ) { $args{'size_units'} = 'IN' } unless ( $args{'length'} ) { $args{'length'} = '5' } unless ( $args{'width'} ) { $args{'width'} = '5' } unless ( $args{'height'} ) { $args{'height'} = '5' } unless ( $args{'dropoff_type'} ) { $args{'dropoff_type'} = 'REGULAR_PICKUP' }
Valid weight_units values are LB, KG. Valid size_units are IN, CM. Valid dropoff_types are REGULAR_PICKUP, BUSINESS_SERVICE_CENTER, DROP_BOX, REQUEST_COURIER, STATION.
- $obj->err_msg()
Returns last posted error message. Usually checked after a false return from one of the methods above.
EXPORT
None by default.
SEE ALSO
Business::FedEx::DirectConnect may work but I could not find the URI to use with this method and I found out that the Ship Manager API is depreciated and will be turned off in 2012
AUTHOR
Steve Troxel, <troxel @ REMOVEMEperlworks.com > with contributions and bug fixes from Kyle Albritton.
COPYRIGHT AND LICENSE
Copyright (C) 2010 by Steven Troxel
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.