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 = [
          {
            'Amount' => '112.93',
            'ServiceType' => 'FIRST_OVERNIGHT'
          },
          {
            'Amount' => '48.91',
            'ServiceType' => 'PRIORITY_OVERNIGHT'
          },
          {
            'Amount' => '75.04',
            'ServiceType' => 'STANDARD_OVERNIGHT'
          },
          {
            'Amount' => '42.84',
            'ServiceType' => 'FEDEX_2_DAY'
          },
          {
            'Amount' => '28.81',
            'ServiceType' => 'FEDEX_EXPRESS_SAVER'
          },
          {
            'Amount' => '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 either published but I as 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

METHODS

$obj->new(%hash)

The new method is the constructor.

The input hash must include the following:

   uri     	  
   account    
   meter   	  
	key        
   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{'lnght_units'} = 'IN' } 
unless ( $args{'length'}       ) { $args{'length'} = '5' } 
unless ( $args{'width'}        ) { $args{'width'}  = '5' } 
unless ( $args{'height'}       ) { $args{'height'} = '5' } 
$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 >

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.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 342:

You forgot a '=back' before '=head1'