Here's my guess: the story tells us that we should look at people's hearts, not their appearance. And that it doesn't matter what others think of you, as long as you set a good goal for yourself. The duckling wished to be as beautiful as a swan, but what he didn't know was that he already had it in him, but to see it he had to endure many hardships. If he had given up all hope and let himself die during winter, he wouldn't have seen himself become a beautiful swan in the end.
The duckling wasn't really ugly, he just didn't belong with the other ducks and geese. He was in fact different, and more beautiful, but they thought him ugly and stupid. Sometimes people don't understand, and mock others who are perhaps better than them. Andersen was known to not have much luck with the ladies, and the sad tone to many of his stories are probably the result of his real life heartaches.