* selena brewington via RT <bug-Business-Shipping@rt.cpan.org> [2004-09-28 15:39]:
Show quoted text> I'm trying to set up a rate quoting system for UPS for some sales
> people. I just installed the Business::Shipping bundle and within a
> few minutes had my test quote script working! Very exciting.
> Excellent set of modules.
Thanks, you're welcome.
Show quoted text> Then, my boss comes in and asks about getting all the available rates
> quoted at the same time. Digging through the UPS documentation I
> discovered that there is a parameter called "RequestOption" and "shop".
> I figured out how to plonk that into $request_tree, however handling
> the response appears to be a little more problematic. Thankfully, the
> response from the test server appears appropriate to the request.
>
> I am not experienced with XML parsing, but given a small nudge could
> probably press into service any suggested subroutines. Could you offer
> any advice? (or maybe some mailing list I should talk to regarding
> this..)
That would be a great feature, and I'll help the best I can.
Starting at line 383 of lib/Business/Shipping/UPS_Online/RateRequest.pm:
my $total_charges = $resp[...]
Right now it just gets the total_charges. Instead, it shoudl get an array of
hashes:
[
service_name => total_cost,
service_name_2 => total_cost2,
]
Maybe even more information than that.
The current system uses a simple multi-level hash to store the price result.
You can see how it is created on line 401 of the same file.
$rate_request->results(
'UPS_Online' => [
{
charges => 5.99,
}
]
);
It was meant to be able to handle multiple packages. You might modify it to be:
$rate_request->results(
'UPS_Online' => [
{
GNDRES => {
charges => 5.99,
estimated_delivery_time => 'Next Tuesday',
},
2DA => {
charges => 15.00,
estimated_delivery_time => 'Thursday',
},
#etc.
}
]
);
Then, you need to modify total_charges() in lib/Business/Shipping/RateRequest.pm
to handle the new structure.
There's also the matter of how the user will specify if they want to "shop" the
rates. Maybe just allow a service => 'shop' parameter? Plus the user needs a
convenient method to browse the new results. I had this in my TODO file, a
suggestion from perlmonks.org:
* [Enh] Have an API for "give me all shipping options and prices for this
source, destination, and weight".
use Business::Shipping;
my $rate_request = Business::Shipping->rate_request(
shipper => 'All',
to_zip => '...',
from_zip => '...',
);
my $results = $rate_request->go() or die $rate_requet->error();
foreach my $shipper ( $@results ) {
print "Shipper Name: $shipper->{name}\n";
foreach my $service ( $shipper->{ 'services' } ) {
print " Service: $service->{name}\n";
print " Price: $service->{total_charges}\n";
}
}
I hope that helps!
--
Daniel Browning <db@kavod.com> - Kavod Technologies. Random Fortune:
The Ancient Doctrine of Mind Over Matter:
I don't mind... and you don't matter.
-- As revealed to reporter G. Rivera by Swami Havabanana