Java: Get The Status Of Multiple Letters with GetLetterStatusRange()

Download Download Java samples [.zip]. Find this sample in directory /test/com/postalmethods/client

package com.postalmethods.client;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
 
import java.util.ArrayList;
import java.util.List;
 
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.GetLetterStatusRangeResponse;
import com.postalmethods.client.api.SendLetterResponse;
import com.postalmethods.client.model.LetterStatus;
 
public class GetLetterStatusRangeTest {
 
    private PostalMethodsClient client;
    private int letterId1, letterId2;
 
    @Before
    public void setUp() {
 
        client = new PostalMethodsClientFactory().build(TestConstants.USERNAME, TestConstants.PASSWORD);
 
        // Send a sample letter so we have a letterId to check status on.
        SendLetterResponse sendResponse = client.sendLetter("Junit test letter 1", TestConstants.SAMPLE_LETTER_FILENAME);
        int code = sendResponse.getResult().getCode();
        assertTrue(code > 0 );
        this.letterId1 = code;
 
        sendResponse = client.sendLetter("Junit test letter 2", TestConstants.SAMPLE_LETTER_FILENAME);
        code = sendResponse.getResult().getCode();
        assertTrue(code > 0 );
        this.letterId2 = code;
    }
 
    @Test
    public void testGetLetterStatus() {
 
        List<Integer> letterIds = new ArrayList<Integer>(2);
        letterIds.add(letterId1);
        letterIds.add(letterId2);
 
        System.out.println("Making call to GetLetterStatusRange...");
        GetLetterStatusRangeResponse response = client.getLetterStatusRange(letterId1,letterId2);
        System.out.println("Service call completed:\n" + response.getResult().toString());
        int code = response.getResult().getCode();
        assertEquals( -3000, code ); // success
 
        List<LetterStatus> letterStatusList = response.getLeterStatusList();
        assertEquals(2,letterStatusList.size());
 
        System.out.println("\n------\nLetter 1 status:\n" + letterStatusList.get(0) + "\n------");
        System.out.println("Letter 2 status:\n" + letterStatusList.get(1) + "\n------");
    }
}