Java: Send A Letter By Providing The Document Content
Download our Java samples from this page.
Find this sample in directory /test/com/postalmethods/client
Find this sample in directory /test/com/postalmethods/client
This sample demonstrates how to send a letter through PostalMethods using the Address Outside method when the content of the document are provided directly instead of reading the document from the file system.
package com.postalmethods.client; import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import com.postalmethods.client.api.SendLetterAndAddressResponse; import com.postalmethods.client.model.Address; import com.postalmethods.client.model.LetterContent; import com.postalmethods.client.model.StringLetterContent; /** * Integration test that calls the SendLetterAndAddress web method. * <p> * For details about PostalMethods.SendLetterAndAddress see * <a href="http://www.postalmethods.com/method/2009-02-26/SendLetterAndAddress">the PostalMethods.SendLetterAndAddress reference</a> */ public class SendLetterAndAddressWithStringLetterContent { private PostalMethodsClient client; @Before public void setUp() { client = new PostalMethodsClientFactory().build(); } @Test public void testSendLetterAndAddressAsString() { Address address = new Address("George Washington", "", "The White House", "1600 Pennsylvania Ave", "", "Washington", "DC", "20500", "USA"); String description = "Test letter with address."; LetterContent letterContent = new StringLetterContent( "<html><body><h2>I just called to say 'I Love You'</h2></body></html>.", "HTML" ); System.out.println("Making call to SendLetterAndAddress..."); SendLetterAndAddressResponse response = client.sendLetterAndAddress(description, letterContent, address); System.out.println("Service call completed:\n" + response.getResult().toString()); int code = response.getResult().getCode(); assertTrue(code > 0); System.out.println("New letter id is: " + code); } }
