Actually, it wasn't intended specifically to set an example, but it did serve to deliver a message that Alexander was not someone who was going to just go away. Alexander's father, Phillip, was murdered in 336 BC, leaving Alexander to rule in his place. Many states, including Thebes and Athens, rose up in revolt when they heard the news. Alexander responded immediately by taking a cavalry force of 3000 men to put down the revolt.
Alexander and his cavalry were able to surprise the city of Thessalonika, resulting in their surrender and also resulted in the Thessalians joining Alexander's cavalry. From there he advanced on Thermopylae and Corinth, and then Athens settled for peace. While he was in Corinth, Alexander was given the title of "Hegemon", or leader, of the Greek forces against the Persians.
From here, Alexander had to move north and put down uprisings in Thrace and then Illyria before he could feel comfortable setting off against the Persians. When he was finally able to move back into southern Greece, he found that he still had to deal with the city of Thebes.
A full year had passed since Phillip's death, and Thebes was the last place to resist accepting Alexander as their leader. Although he tried several times to send ambassadors requesting that the city surrender on peaceful terms, they stubbornly refused. As a result, he had no choice and had to advance on the city, leaving it totally destroyed.
To say that Alexander intentionally destroyed Thebes to set an example would probably be overstating things. By the time he came to Thebes, the rest of Greece had pretty much accepted his leadership. It may be true that he destroyed the city to set an example of what would happen to others who may choose to defy him, but he didn't appear to have set out with that intention.
See Alexander's Balkan Campaign to read some more information.