Java: Send A Letter With SendLetter()

Download
Download our Java samples from this page.
Find this sample in directory /test/com/postalmethods/client

This sample demonstrates how to send a letter through PostalMethods using the Address Inside method.

package com.postalmethods.client;
 
import static org.junit.Assert.assertTrue;
 
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.SendLetterResponse;
 
/**
 * Integration test that calls the SendLetter web method.
 * <p>
 * For details about PostalMethods.SendLetter see 
 * <a href="http://www.postalmethods.com/method/2009-02-26/SendLetter">the PostalMethods.SendLetter reference</a>
 */
public class SendLetterTest {
 
    private PostalMethodsClient client;
 
    @Before
    public void setUp() {
        client = new PostalMethodsClientFactory().build();
    }
 
    @Test
    public void testSendLetter() {
        System.out.println("Making call to SendLetter...");
        SendLetterResponse response = client.sendLetter("Sending test letter via JUnit integration test.", TestConstants.SAMPLE_LETTER_FILENAME);
        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);
    }
}