Dev - usps Rate Estimates

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Dev - usps Rate Estimates

Daniel Kunkel
Hi

I think I finally tracked down most of the problems with
uspsRateEstimates, but I need a little help...  

The three issues I found:  

1.) The Pounds in the request sent to the USPS must be a non decimal
number.

2.) httpClient messes up the get request by converting the & separating
the variables to &.

3.) The software is currently doing a post, when I've been testing a get
which seems to work a lot better.

Solutions:

1.)  Line 173 - shipment.thirdparty.usps.UspsServices

            double weightPounds = Math.floor(packageWeight);
            double weightOunces = Math.ceil(packageWeight % weightPounds
* 16);
            DecimalFormat df = new DecimalFormat("#");
            UtilXml.addChildElementValue(packageElement, "Pounds",
df.format(weightPounds), requestDocument);
            UtilXml.addChildElementValue(packageElement, "Ounces",
df.format(weightOunces), requestDocument);


2.)  

The request actually sent is:
http://api.com/ShippingAPI.dll?API=Rate&XML=%3CRateReque...

The & in the get should be a &

The code in question:

        HttpClient http = new HttpClient(conUrl);
        http.setTimeout(timeout * 1000);
        http.setParameter("API", requestType);
        http.setParameter("XML", xmlString);

        String responseString = null;
        try {
            responseString = http.get();
        } catch (HttpClientException e) {
            throw new UspsRequestException("Problem connecting with USPS
server", e);
        }


I don't understand why it's converting the &,  but I'm pretty sure
someone on this mailing list will.

3.) About Line 1306 - shipment.thirdparty.usps.UspsServices

            responseString = http.get();  // not post


-------------

I still need to add code that will convert other product weights beside
pounds into pounds for the usps mailing request...  then I can provide a
patch.

Thanks

--
Daniel

*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-
Have a GREAT Day!

Daniel Kunkel           [hidden email]
BioWaves, LLC           http://www.BioWaves.com
14150 NE 20th St. Suite F1
Bellevue, WA 98007
800-734-3588    425-895-0050
http://www.WizCity.com  http://www.Illusion-Optical.com
*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - usps Rate Estimates

Daniel Kunkel
Hi

Ok...  I'm moving forward with fixing USPS... but before I wanted to
check for feedback first.

I need to switch the USPS requests from post to get, and I currently see
a few options, and wonder which is preferred...

1.) Use the GetMethod of httpClient.

2.) Use the java.net.Socket interface.

3.) Use the SocketFactory interface (which I think uses the
java.net.Scoket interface.

4.) Use another interface I haven't noticed yet.

Is one method preferred over the others? Are any depreciated?

Thanks



On Thu, 2006-01-05 at 14:15 -0800, Daniel Kunkel wrote:

> Hi
>
> I think I finally tracked down most of the problems with
> uspsRateEstimates, but I need a little help...  
>
> The three issues I found:  
>
> 1.) The Pounds in the request sent to the USPS must be a non decimal
> number.
>
> 2.) httpClient messes up the get request by converting the & separating
> the variables to &.
>
> 3.) The software is currently doing a post, when I've been testing a get
> which seems to work a lot better.
>
> Solutions:
>
> 1.)  Line 173 - shipment.thirdparty.usps.UspsServices
>
>             double weightPounds = Math.floor(packageWeight);
>             double weightOunces = Math.ceil(packageWeight % weightPounds
> * 16);
>             DecimalFormat df = new DecimalFormat("#");
>             UtilXml.addChildElementValue(packageElement, "Pounds",
> df.format(weightPounds), requestDocument);
>             UtilXml.addChildElementValue(packageElement, "Ounces",
> df.format(weightOunces), requestDocument);
>
>
> 2.)  
>
> The request actually sent is:
> http://api.com/ShippingAPI.dll?API=Rate&XML=%3CRateReque...
>
> The & in the get should be a &
>
> The code in question:
>
>         HttpClient http = new HttpClient(conUrl);
>         http.setTimeout(timeout * 1000);
>         http.setParameter("API", requestType);
>         http.setParameter("XML", xmlString);
>
>         String responseString = null;
>         try {
>             responseString = http.get();
>         } catch (HttpClientException e) {
>             throw new UspsRequestException("Problem connecting with USPS
> server", e);
>         }
>
>
> I don't understand why it's converting the &,  but I'm pretty sure
> someone on this mailing list will.
>
> 3.) About Line 1306 - shipment.thirdparty.usps.UspsServices
>
>             responseString = http.get();  // not post
>
>
> -------------
>
> I still need to add code that will convert other product weights beside
> pounds into pounds for the usps mailing request...  then I can provide a
> patch.
>
> Thanks
>
--
Daniel

*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-
Have a GREAT Day!

Daniel Kunkel           [hidden email]
BioWaves, LLC           http://www.BioWaves.com
14150 NE 20th St. Suite F1
Bellevue, WA 98007
800-734-3588    425-895-0050
http://www.WizCity.com  http://www.Illusion-Optical.com
*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - usps Rate Estimates

David E. Jones

Daniel,

I saw the patch you submitted and I'll try to get to it in the next  
few days.

I think changing the HttpClient to not expand "&" to "&" is a  
good idea because it really shouldn't do that there. HTTP clients  
don't send "&" in the URL, that should only go in the HTML  
documents and then the browser reduces it to a "&". So, in an HTML  
document it is good (and in XHTML required), but in URLs ready to  
send to the server it is bad, and never should have been put in there...

-David


On Jan 6, 2006, at 7:35 PM, Daniel Kunkel wrote:

> Hi
>
> Ok...  I'm moving forward with fixing USPS... but before I wanted to
> check for feedback first.
>
> I need to switch the USPS requests from post to get, and I  
> currently see
> a few options, and wonder which is preferred...
>
> 1.) Use the GetMethod of httpClient.
>
> 2.) Use the java.net.Socket interface.
>
> 3.) Use the SocketFactory interface (which I think uses the
> java.net.Scoket interface.
>
> 4.) Use another interface I haven't noticed yet.
>
> Is one method preferred over the others? Are any depreciated?
>
> Thanks
>
>
>
> On Thu, 2006-01-05 at 14:15 -0800, Daniel Kunkel wrote:
>> Hi
>>
>> I think I finally tracked down most of the problems with
>> uspsRateEstimates, but I need a little help...
>>
>> The three issues I found:
>>
>> 1.) The Pounds in the request sent to the USPS must be a non decimal
>> number.
>>
>> 2.) httpClient messes up the get request by converting the &  
>> separating
>> the variables to &.
>>
>> 3.) The software is currently doing a post, when I've been testing  
>> a get
>> which seems to work a lot better.
>>
>> Solutions:
>>
>> 1.)  Line 173 - shipment.thirdparty.usps.UspsServices
>>
>>             double weightPounds = Math.floor(packageWeight);
>>             double weightOunces = Math.ceil(packageWeight %  
>> weightPounds
>> * 16);
>>             DecimalFormat df = new DecimalFormat("#");
>>             UtilXml.addChildElementValue(packageElement, "Pounds",
>> df.format(weightPounds), requestDocument);
>>             UtilXml.addChildElementValue(packageElement, "Ounces",
>> df.format(weightOunces), requestDocument);
>>
>>
>> 2.)
>>
>> The request actually sent is:
>> http://api.com/ShippingAPI.dll?API=Rate&XML=%3CRateReque...
>>
>> The & in the get should be a &
>>
>> The code in question:
>>
>>         HttpClient http = new HttpClient(conUrl);
>>         http.setTimeout(timeout * 1000);
>>         http.setParameter("API", requestType);
>>         http.setParameter("XML", xmlString);
>>
>>         String responseString = null;
>>         try {
>>             responseString = http.get();
>>         } catch (HttpClientException e) {
>>             throw new UspsRequestException("Problem connecting  
>> with USPS
>> server", e);
>>         }
>>
>>
>> I don't understand why it's converting the &,  but I'm pretty sure
>> someone on this mailing list will.
>>
>> 3.) About Line 1306 - shipment.thirdparty.usps.UspsServices
>>
>>             responseString = http.get();  // not post
>>
>>
>> -------------
>>
>> I still need to add code that will convert other product weights  
>> beside
>> pounds into pounds for the usps mailing request...  then I can  
>> provide a
>> patch.
>>
>> Thanks
>>
> --
> Daniel
>
> *-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-
> Have a GREAT Day!
>
> Daniel Kunkel           [hidden email]
> BioWaves, LLC           http://www.BioWaves.com
> 14150 NE 20th St. Suite F1
> Bellevue, WA 98007
> 800-734-3588    425-895-0050
> http://www.WizCity.com  http://www.Illusion-Optical.com
> *-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-
>
>
> _______________________________________________
> Dev mailing list
> [hidden email]
> http://lists.ofbiz.org/mailman/listinfo/dev

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev
Reply | Threaded
Open this post in threaded view
|

Re: Dev - usps Rate Estimates

Daniel Kunkel
Thank you David.  

I wasn't sure that & wasn't some sort of xml get protocol, and
wasn't particularly fond of changing code that could effect (read break)
other parts of OFBiz without raising a flag.

Re the patch...  The most important change to review is how I was
reading the product weight UOM into the routine... I think I'm reading
the right field, but it was always null, so I'm not so sure.

----

A few bits of business going forward on the module...

1.) Breaking Something when USPS hands back an error.

Right now the module defaults to $1 when an error is returned... This is
unacceptable!  However, I haven't figured out what I want to have
happen, much less what is possible in terms of "breaking" the shipping
estimate system when that happens...

It could help to show an error on the page that "Shipping isn't working,
the shipping will be calculated and charged later." is possibly the best
solution, but could lead to unhappy customers that "ignore" that.

2.) Flat Rate Boxes

USPS has another version (RateV2Request) of their interface that handles
flat rate boxes...   I'm not intending to implement this.

3.) International Shipping Messages

The USPS International system has a really excellent system of passing
back messages and shipping limitations for the various countries...

For example:

<Prohibitions>Articles made of tortoise-shell, mother of pearl, ivory,
bone meerschaum and amber (succin), natural or reconstructed, worked
jade and mineral substances similar to jade.</Prohibitions>

<Restrictions>Articles of gold or platinum, jewelry and precious stones
must be licensed by the Algerian Ministry of Finance. Coins, banknotes,
negotiable securities, checks and other instruments of payment, may only
be imported by the Central Bank of Algeria or approved intermediary
banks.</Restrictions>

<Observations>Import permits or licenses are required for many types of
goods; therefore, the sender should ascertain from the addressee before
mailing whether the necessary documents are held.</Observations>

<CustomsForms>Postal Union Mail (LC/AO): PS Form 2976 or 2976-A (see
123.61) Parcel Post: PS Form 2976-A inside 2976-E
(envelope)</CustomsForms>

<ExpressMail>Postal employees must tell customers that there is no
service guarantee on any EMS item to Algeria. Country Code DZ Reciprocal
Service Name EMS Required Customs Form/Endorsement 1. For correspondence
and business papers: PS Form 2976, Customs - CN 22 (Old C 1) and
Sender's Declaration (green label). Endorse item clearly next to mailing
label as BUSINESS PAPERS.</ExpressMail>

<AreasServed>Adrar RP Ain Benian Ain Defla RP Ain Smara Ain Temouchent
RP Alger aeroport EMS</AreasServed>


It seems like this information could be worth noting, or saving in the
shipping notes for some companies, while it would be inappropriate for
others.

Any thoughts?

4.) Product Packing Factor

I wonder if other companies would find it useful to have a measure of
how much packing will be needed for various products...


Packaging materials can vary from ounces to a pound or more, which can
be a factor for certain business.

For ourselves, we are looking at adjusting our product weights to better
estimate how much the packing materials will weigh, especially in cases
where they will bring the weight up over the next pound.

Would it be worth creating some sort of variable that would take into
account the packaging weight and requirements for each products?

Anyone have experience with other solutions to this problem?

Thanks

--
Daniel

*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-
Have a GREAT Day!

Daniel Kunkel           [hidden email]
BioWaves, LLC           http://www.BioWaves.com
14150 NE 20th St. Suite F1
Bellevue, WA 98007
800-734-3588    425-895-0050
http://www.WizCity.com  http://www.Illusion-Optical.com
*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-.,,.-*"*-

 
_______________________________________________
Dev mailing list
[hidden email]
http://lists.ofbiz.org/mailman/listinfo/dev