i need to retreive a rate quote from ups with php. i know how to parse the xml response, but my problem is <b>i dont know the url to send the request</b>.
in the past, i did the same thing with a shipping company called gi trucking. it sent a GET request to their server. their server responded with an xml document, then i parsed it and got the grand total. here is how that worked:
<?php
function gicalculate ($origzip, $destzip, $itemweight) {
//talk to gi, they will respond with xml text
for ($o=0; $o < count($itemweight); $o++) {
$itemstogetquoted .= "&QCCL" . ($o + 1) . "=70.0&QCSWT" . ($o + 1) . "=" . $itemweight[$o];
}
$fp = @file("http://www.gi-trucking.com/cgi-dta/qun100.mbr/output?QCFROM=" . $origzip . "&QCTO=" . $destzip . $itemstogetquoted . "&QCDWP=S&QCDTRM=P&QCDAC1=&QCDAC2=&QCDAC3=&format=xml&user_name=xxxxx&password=xxxxx", "r");
for ($i=0; $i < count($fp); $i++) {
$xmlstr .= $fp[$i];
}
//parse the xml text to find the cost
$strstart = strpos($xmlstr, "<netfreightcharges>");
$strstop = strpos($xmlstr, "</netfreightcharges>");
$netcost = substr($xmlstr, $strstart + 19, ($strstop - ($strstart + 19)));
$handling_fee = 25.00; //add a standard handling fee of 25 bucks
$grosscost = $netcost + $handling_fee;
$grosscost = number_format($grosscost, 2, ".", ",");
//do a final error check to determine if what we got back from GI is valid
if ($grosscost != "" and $grosscost != ".00" and is_numeric($grosscost)) {
//return a good value
return $grosscost;
} else {
return "error";
}
}
?>
i have already looked on ups.com. i registered for all of their tools that they have, but their support docs are just a bunch of nonsense. they are packed with trillions of pdfs that say nothing. i just need the url that i need to send a request to. anyone had any experience with ups in the past?
:eek: